from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView

from apps.users.models import User


class UserDailyActiveCountView(APIView):
    permission_classes = [IsAdminUser]

    def get(self, request):
        # 获取当前日期
        from datetime import date
        today = date.today()
        # 获取用户数据
        count = User.objects.filter(last_login__gte=today).count()
        # 返回数据
        return Response({"count": count})
